package com.qms.repast.ui.presenter;

import android.app.Activity;

import com.google.gson.Gson;
import com.orhanobut.logger.Logger;
import com.qms.repast.commons.Constants;
import com.qms.repast.entity.resbean.BannerBean;
import com.qms.repast.entity.resbean.BannerBean.BodyBean.InfoBean;
import com.qms.repast.module.UserModule;
import com.qms.repast.ui.base.BasePresenter;
import com.qms.repast.ui.view.IReserveView;

import java.util.List;

import io.reactivex.observers.DisposableObserver;

/**
 * @author 泅渡者
 * @date 2018/9/20 0020
 * @describe:
 */
public class ReservePresenter extends BasePresenter<IReserveView> {
	protected UserModule userModule;

	public ReservePresenter (Activity mContext, IReserveView mView) {
		super(mContext, mView);
		userModule = new UserModule(mContext);
	}

	/**
	 * 获取带缓存的轮播图
	 */
	public void getBannerList () {
		userModule.reqBannerList(new DisposableObserver<BannerBean>() {
			@Override
			public void onError (Throwable throwable) {
				Logger.e(throwable.getMessage());
			}

			@Override
			public void onComplete () {
				Logger.d("Request is End");
			}

			@Override
			public void onNext (BannerBean bannerBean) {
				Logger.json(new Gson().toJson(bannerBean));
				if (Constants.OLDRESULTCODE.equals(bannerBean.getHeader().getStatusCode())) {
					List<InfoBean> beanList = bannerBean.getBody().getInfo();
					if (beanList != null && beanList.size() > 0) {
						mView.initBanner(beanList);
					}
				}
			}
		});
	}


}
